{{if function_used "timestr"}}{{import "dayjs"}}
{{end}}{{if function_used "md5"}}{{import "md5"}}
{{end}}{{if function_used "timestr"}}
const timestr= (fmt) => {
  return dayjs().format(fmt);
}{{end}}{{if function_used "md5"}}
const md5= (str) => {
  return md5(str);
}{{end}}
const verify= (par, name, option) =>{
  if (option.required && par == undefined){
    return Promise.reject("参数"+name+"要求必传，但未传入");
  }
}
const objToForm = (obj, bodyFormData, prefix = "") =>{

  if (typeof obj == "object") {
    if (obj instanceof Blob){
      bodyFormData.set(prefix, obj);
    }
    for (const [key, value] of Object.entries(obj)) {
      if (typeof value == "object") {
        var keyForLoop = ""
        if (prefix) {
          keyForLoop = prefix + "[" + key + "]"
        } else {
          keyForLoop = key
        }
        if (Array.isArray(value)) {
          for (let index = 0; index < value.length; index++) {
            const item = value[index];
            objToForm(item, bodyFormData, keyForLoop + `[${index}]`)
          }
        } else {
          objToForm(value, bodyFormData, keyForLoop)
        }
      } else if (prefix) {
        bodyFormData.set(prefix + "[" + key + "]", value);
      } else {
        bodyFormData.set(key, value);
      }
    }
  } else if (prefix && !!obj) {
    bodyFormData.set(prefix, obj);
  }
}

{{export_str}}{
  {{if function_used "timestr"}}timestr,
  {{end}}{{if function_used "md5"}}md5,
  {{end}}verify,
  objToForm
}